const Mock = require('mockjs');

// 模拟频道列表数据
const channelList = [
    { id: 1, name: '推荐' },
    { id: 2, name: '热点' },
    { id: 3, name: '科技' },
    { id: 4, name: '娱乐' },
    { id: 5, name: '游戏' },
    { id: 6, name: '体育' },
    { id: 7, name: '财经' },
    { id: 8, name: '军事' }
];

// 导出mock数据
module.exports = function (app) {
    const cartData = Mock.mock({
        'list|1-10': [{
            'id|+1': 1,
            'name': function() {
                return Mock.Random.pick(channelList).name;
            },
            'price': '@natural(100, 1000)',
            'image': '@image("50x50", "#ccc", "#FFF", "png", "商品")',
            'quantity': '@natural(1, 5)',
            'model': '@ctitle(2, 4)'
        }]
    })

    app.get('/api/v1_0/channel', (req, res, next) => {
        res.header('Access-Control-Allow-Origin', '*');
        res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
        res.header('Access-Control-Allow-Headers', 'Content-Type');
        res.json({
            code: 0,
            data: cartData.list
        })
    })

    app.post('/api/v1_0/channel/update', (req, res) => {
        const { id, name } = req.body
        res.json({
            code: 0,
            data: {
                id,
                name
            }
        })
    })
};